<template>
  <el-form ref="form" :model="order" style="width:30%" label-width="80px">
    <el-form-item label="订单来源">
      <el-select v-model="order.paymentWay" placeholder="请选择订单来源">
        <el-option value="淘宝"></el-option>
        <el-option value="天猫"></el-option>
        <el-option value="天猫平台"></el-option>
        <el-option value="支付宝"></el-option>
        <el-option value="微信小程序"></el-option>
        <el-option value="中保车服"></el-option>
        <el-option value="大蜂保代"></el-option>
        <el-option value="93应用"></el-option>
        <el-option value="路灵灵App"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="车牌号">
      <el-input v-model="order.carPlate"></el-input>
    </el-form-item>
    <el-form-item label="预检时间" prop="placeTestTime">
      <el-date-picker
        type="datetime"
        placeholder="选择日期"
        v-model="order.placeTestTime"
        style="width: 100%;"
      ></el-date-picker>
    </el-form-item>
    <el-form-item label="实付价格">
      <el-input v-model="order.price"></el-input>
    </el-form-item>
    <el-form-item label="客户姓名">
      <el-input v-model="order.customerName"></el-input>
    </el-form-item>
    <el-form-item label="客户电话">
      <el-input v-model="order.phone" maxlength="11"></el-input>
    </el-form-item>
    <el-form-item label="居住地址" prop="address">
      <pickArea @getSite="setArea" />
      <el-input v-model="order.address"></el-input>
    </el-form-item>
    <el-form-item label="行驶证或车辆照片" prop="licenseImgs">
      <el-upload
        class="upload-demo"
        drag
        :action="this.$http.defaults.baseURL+'/file/uploadFile'"
        multiple
        :on-success="getLicenseImgs"
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">只能上传jpg/png文件，且不超过500kb</div>
      </el-upload>
    </el-form-item>
    <el-form-item label="电子保单(非必填)" prop="policyImgs">
      <el-upload
        class="upload-demo"
        drag
        :action="this.$http.defaults.baseURL+'/file/uploadFile'"
        multiple
        :on-success="getPolicyImgs"
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">只能上传jpg/png文件，且不超过500kb</div>
      </el-upload>
    </el-form-item>
    <el-form-item label="备注">
      <el-input type="textarea" v-model="order.remarks"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">立即创建</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import pickArea from "@/components/pickArea.vue";
export default {
  components: {
    pickArea
  },
  data: function() {
    let currentUser = this.$store.state.LoginModule.currentUser;
    return {
      order: {
        carPlate: "",
        price: 0,
        customerName: "",
        phone: "",
        province: "",
        city: "",
        area: "",
        address: "",
        paymentWay: "",
        placeTestTime: "",
        licenseImgs: [],
        policyImgs: [],
        remarks: "",
        declareName: currentUser.username
      }
    };
  },
  methods: {
    onSubmit: async function() {
      const { data } = await this.$http.post(
        `/order/placeCStoreOrder`,
        this.order
      );
      if (data.code == 1) {
        this.$message({
          message: data.message,
          type: "success"
        });
        this.$router.push("/driverOrder");
      } else {
        this.$message({
          message: data.message,
          type: "error"
        });
      }
    },
    setArea: function(province, city, area) {
      this.order.province = province;
      this.order.city = city;
      this.order.area = area;
    },
    getLicenseImgs: function(res, file, fileList) {
      this.order.licenseImgs.push(res.object.url);
    },
    getPolicyImgs: function(res, file, fileList) {
      this.order.policyImgs.push(res.object.url);
    }
  }
};
</script>
<style>
</style>
